package com.sjzl.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 版块
 * @author 黄健
 */
@Entity
@Table(name="tb_board")
public class Board extends BaseEntity {
	
	private String name;
	private String description;
	private Board board;
	private List<Board> subBoard = new ArrayList<Board>();
	private List<Post> posts = new ArrayList<Post>();
	
	/**
	 * 帖子数
	 */
	private Integer postCount;
	/**
	 * 回帖总数
	 */
	private Integer replyCount;
	
	/**
	 * 最后帖子
	 */
	private Post lastPost;
	
	/**
	 * 版主
	 */
	private List<User> moderators = new ArrayList<User>();
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
	@JoinColumn(name="parent_id")
	public Board getBoard() {
		return board;
	}
	public void setBoard(Board board) {
		this.board = board;
	}
	
	@OneToMany(fetch = FetchType.EAGER, mappedBy="board", cascade = CascadeType.REMOVE)
	public List<Board> getSubBoard() {
		return subBoard;
	}
	public void setSubBoard(List<Board> subBoard) {
		this.subBoard = subBoard;
	}
	
	public Integer getPostCount() {
		return postCount;
	}
	public void setPostCount(Integer postCount) {
		this.postCount = postCount;
	}
	
	public Integer getReplyCount() {
		return replyCount;
	}
	public void setReplyCount(Integer replyCount) {
		this.replyCount = replyCount;
	}
	
	@ManyToOne
	@JoinColumn(name = "last_post_id")
	public Post getLastPost() {
		return lastPost;
	}
	public void setLastPost(Post lastPost) {
		this.lastPost = lastPost;
	}
	
	@ManyToMany
	@JoinTable(name = "board_moderator", joinColumns = { @JoinColumn(name = "board_id") }, inverseJoinColumns = { @JoinColumn(name = "user_id") })
	public List<User> getModerators() {
		return moderators;
	}
	public void setModerators(List<User> moderators) {
		this.moderators = moderators;
	}
	
	@OneToMany(mappedBy = "board")
	public List<Post> getPosts() {
		return posts;
	}
	public void setPosts(List<Post> posts) {
		this.posts = posts;
	}
	
}
